package com.example.tetris.Tetris;

import ohos.aafwk.ability.Ability;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;

//绘制俄罗斯方块边框
public class TetrisBorder extends TetrisBase {
    //定义边框线的颜色
    protected Color borderColor = new Color(Color.rgb(135,147,115));
    //定义边框线宽度(4像素)
    protected int borderLineWidth=4;

    //构造方法的第一种重载形式
    public TetrisBorder(Ability ability, Component component, int[][] drawBlock) {
//        调用父类的构造函数为子类属性赋值
        super(ability, component, drawBlock);
    }
    //构造方法的第二种重载形式
    public TetrisBorder(Ability ability, Component component) {
        super(ability, component);
    }

    //在onDraw方法中绘制边框线
    public void onDraw(Component component, Canvas canvas){
//        super 方法还可以调用父类的函数
        super.onDraw(component,canvas);
        //初始化画笔
        Paint paint = new Paint();
        //设置边框线的宽度
        paint.setStrokeWidth(borderLineWidth);
        //设置边框线为实现
        paint.setStyle(Paint.Style.STROKE_STYLE);
        //设置边框线颜色
        paint.setColor(borderColor);
        //计算边框线右边的位置
        float right = colCount*cellSize+(colCount+1)*cellSpace;
        //计算边框线底边的位置
        float bottom = rowCount*cellSize+(rowCount+1)*cellSpace;
        //绘制一个矩形作为游戏界面边框线
        canvas.drawRect(new RectFloat(0,0,right,bottom),paint);


    }
}
